﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;

namespace AthleteService
{
    public class DBConnection3
    {
        private SqlConnection connection;
        public string sel;
        public string choice;
        public DBConnection3(string sel, string choice)
        {
            try
            {
                connection = new SqlConnection(@"server=.;database=sportmeet;user=sa;pwd=Jackson.yi11.28");
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            this.sel = sel;
            this.choice = choice;
        }
        public DataTable Select()
        {
            try
            {
                string strSql = "";
                connection.Open();
                if (sel.Equals("eno"))
                {
                    strSql = "select eevent.eno 项目编号,eevent.ename 项目名,aname 选手姓名,sutime 比赛时间 from signup ,athlete,eevent where eevent.Eno='" + choice + "'and eevent.eno=signup.eno and signup.ano=athlete.ano";
                }
                if (sel.Equals("Ano"))
                {
                    strSql = "select eevent.eno 项目编号,eevent.ename 项目名,aname 选手姓名,sutime 比赛时间 from signup ,athlete,eevent where signup.ano='" + choice + "'and eevent.eno=signup.eno and signup.ano=athlete.ano";
                }
                SqlCommand cmd = new SqlCommand(strSql, connection);
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                connection.Close();
                return dt;
            }
            catch (Exception es)
            {
                throw new Exception(es.Message);
            }
            finally
            {
                connection.Close();
            }
        }
    }
}